const str = 'ddffqavvbbasss';


function compress(str) {
  let result = '';
  let num = 1;
  let len = str.length;
  for (let i = 0; i < len - 1; i++) {
    if (str[i] === str[i + 1]) {
      num++;
    } else {
      result += str[i] + num;
      num = 1
    }
  }
  result = result + str[len - 1] + num;
  return result;
}

console.log(compress(str))